const { ccclass, property } = cc._decorator;

@ccclass
export default class Game extends cc.Component {

    @property(cc.Node)
    pfbRoot: cc.Node = null

    @property(cc.Prefab)
    record: cc.Prefab = null

    @property(cc.Prefab)
    bgm: cc.Prefab = null

    @property(cc.Prefab)
    game: cc.Prefab = null

    pfbCache: any
    onLoad() {
        this.pfbCache = {}
    }

    btnStart() {
        if (this.pfbCache['game']) {
            this.pfbCache['game'].active = true
        } else {
            let gamePfb = cc.instantiate(this.game)
            gamePfb.parent = this.pfbRoot
            this.pfbCache['game'] = gamePfb
        }
    }

    btnRecord() {
        if (this.pfbCache['record']) {
            this.pfbCache['record'].active = true
        } else {
            let recordPfb = cc.instantiate(this.record)
            recordPfb.parent = this.pfbRoot
            this.pfbCache['record'] = recordPfb
        }
    }

    btnBGM() {
        if (this.pfbCache['bgm']) {
            this.pfbCache['bgm'].active = true
        } else {
            let recordPfb = cc.instantiate(this.bgm)
            recordPfb.parent = this.pfbRoot
            this.pfbCache['bgm'] = recordPfb
        }
    }

    btnExit() {
        cc.game.end()
    }
}